package edu.gyc.exceptionhomework;
import java.util.Random;
class Tank implements Comparable{
    private String name;
    private int weight;
    public Tank(String name, int weight) {
        this.name = name;
        this.weight = weight;
    }
    @Override
    public String toString() {
        return "Tank{" +
                "name='" + name + '\'' +
                ", weight=" + weight +
                '}';
    }
    @Override
    public int compareTo(Object o) {
        Tank tank=(Tank)o;
        if (this.weight > tank.weight) {
            return 1;
        }else if(this.weight<tank.weight){
            return -1;
        }
        return 0;
    }
}
public class HiTank {
    public static void main(String[] args) {
        Tank t1 = new Tank("美国M1A1", 65);
        Tank t2 = new Tank("中国99A", 55);
        System.out.println("比较两个坦克的大小");
        int n = t1.compareTo(t2);
        if (n > 0) {
            System.out.println(t1+"排序在"+t2+"之后");
        }else {
            System.out.println(t1+"排序在"+t2+"之前");
        }
    }
}
